﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.Default.model;
using System.Data.SqlClient;

namespace Jxym.wlkc2011.Module.Default.SERVER.role
{
    public partial class RoleAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string returnValue = "{success:false,msg:'参数不正确'}";
                try
                {
                    if (Request.Params["roletext"] != null)
                    {
                        string text = Request.Params["roletext"];

                        MsSqlDal<User_Role> iUr = new MsSqlDal<User_Role>();

                        SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Name", text) };

                        if (iUr.IsExist("Name=@Name", parameters))
                        {
                            returnValue = "{success:false,msg:'数据库存在同名角色，不允许重复创建'}";
                        }
                        else
                        {
                            if (Request.Params["roleid"] != null)
                            {
                                iUr.Updata("ID=" + Convert.ToInt32(Request.Params["roleid"]), parameters);
                            }
                            else
                            {
                                iUr.Add(parameters);
                            }
                            returnValue = "{success:true,msg:'保存完成'}";
                        }
                    }
                    Response.Write(returnValue); 
                }
                catch
                {
                    Response.Write("{success:false,msg:'参数不正确'}");
                }
            }
        }
    }
}